<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Validate;
use app\common\model\TalkRecord as TalkRecordModel;

/**
 * 用户对话记录接口
 */
class Talkrecord extends Api
{

    /**
     * 用户对话记录列表
     * @var array
     */
    protected $noNeedRight = '*';

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new TalkRecordModel();
    }
    /**
     * 查询用户对话表
     * @ApiTitle    (查询对话表)
     *  @ApiMethod  (POST)
     *  @ApiParams (name="user_id", type="int", required=true, description="用户ID")
     *  @ApiReturnParams   (name="page", type="int", required=true, description="页数")
     *  @ApiReturnParams   (name="limit", type="int", required=true, description="每页条数")
     *  @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     *  @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     *  @ApiReturn   ({
          'code':'200',
          'msg':'查询成功',
          'time': "",
          'data': $row
        })
     */

    public function talkrecordIndex()
    {
        $data = input('post.');
        $userId = $data['user_id'];
        if (!$userId || !Validate::is($userId, 'number')) {
            $this->error('参数错误');
        }

        $page = isset($data['page']) ? intval($data['page']) : 1;
        $limit = isset($data['limit']) ? intval($data['limit']) : 10;

        $dis = [
            'user_id' => $userId,
        ];
        $row = $this->model->dataList($dis, 'id desc', $page, $limit);
        $total = $this->model->dataCount($dis);

        $this->success('查询成功', [
            'data' => $row,
            'total' => $total,  // 总记录数
            'page' => $page,
            'limit' => $limit
        ]);
    }

}